"""FreshSupermarket URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include

from django.conf.urls.static import static  # 上传的文件能直接通过url打开，以及setting中设置

from django.conf import settings
from rest_framework.routers import DefaultRouter
from rest_framework.documentation import include_docs_urls
from rest_framework.authtoken import views as authtoken_view
from rest_framework_simplejwt import views as simplejwt_views  # 引入simplejwt


from goods.views import (
    GoodsListView01, GoodsListView02, GoodsListView03, GoodsListViewSet01, GoodsListViewSet02,
    GoodsListViewSet03, GoodsListViewSet04, GoodsListViewSet05, GoodsListViewSet06, GoodsListViewSet07,
    CategoryViewSet01, CategoryViewSet02, ParentCategoryViewSet01, MyTestView01
)

# goods_list = GoodsListViewSet01.as_view({
#     'get': 'list',
# })
# 创建一个路由器并注册我们的视图集
'''
若有自定义的get_quertset方法，router.register()中必须加上base_name，不然会出现以上错误
'''
router = DefaultRouter()
router.register(r'goods', GoodsListViewSet07)  # 配置goods的url
router.register(r'categories', CategoryViewSet02)  # 配置分类的url
router.register(r'parent_categories', ParentCategoryViewSet01)  # 配置分类的url

urlpatterns = [
    path('admin/', admin.site.urls),


    path('api-auth/', include('rest_framework.urls')),
    path('api-token-auth/', authtoken_view.obtain_auth_token),  # drf token获取的url
    # path('api/token/', simplejwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'),  # simplejwt认证接口
    path('api/token/refresh/', simplejwt_views.TokenRefreshView.as_view(), name='token_refresh'),  # simplejwt认证接口

    path('login/', simplejwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'),  # 登录一般是login
    path('api/token/refresh/', simplejwt_views.TokenRefreshView.as_view(), name='token_refresh'),  # simplejwt认证接口



    path('ckeditor/', include('ckeditor_uploader.urls')),  # 配置富文本编辑器url
    path('', include(router.urls)),  # API url现在由路由器自动确定。
    path('docs/', include_docs_urls(title='DRF文档')),  # DRF文档
    path('test/', MyTestView01.as_view(), name='myTest'),

]

# 上传的文件能直接通过url打开
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
